package net.scalan.jpa.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

@Entity
public class DBCabinetCasette implements Serializable {

    private static final long serialVersionUID = 1L;

    //==========================================================================
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    //==========================================================================
    @Column
    private String name;

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    //==========================================================================
    @Column
    private Integer modulesPerRow;

    /**
     * @return the modulesPerRow
     */
    public Integer getModulesPerRow() {
        return modulesPerRow;
    }

    /**
     * @param modulesPerRow the modulesPerRow to set
     */
    public void setModulesPerRow(Integer modulesPerRow) {
        this.modulesPerRow = modulesPerRow;
    }

    //==========================================================================
    @ManyToOne
    private DBStationCabinet cabinet;

    /**
     * @return the cabinet
     */
    public DBStationCabinet getCabinet() {
        return cabinet;
    }

    /**
     * @param cabinet the cabinet to set
     */
    public void setCabinet(DBStationCabinet cabinet) {
        this.cabinet = cabinet;
    }

    //==========================================================================
    @OneToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE}, fetch = FetchType.LAZY)
    @JoinColumn(name = "casette_id", referencedColumnName = "id")
    private List<DBCasetteModule> modules = new ArrayList<DBCasetteModule>();

    /**
     * @return the modules
     */
    public List<DBCasetteModule> getModules() {
        return modules;
    }

    /**
     * @param modules the modules to set
     */
    public void setModules(List<DBCasetteModule> modules) {
        this.modules = modules;
    }

    //==========================================================================
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof DBCabinetCasette)) {
            return false;
        }
        DBCabinetCasette other = (DBCabinetCasette) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "net.scalan.jpa.model." + this.getClass().getName() + "[id=" + id + "]";
    }
}
